/**
 * 完全容错
 */
function killerr() {
	return true
}
window.onerror = killerr
/**
 * * 容错结束
 */

/*******************************************************************************
 * 浏览器类型,使用方法
 * 
 * //以下进行测试 # if (Sys.ie) document.write('IE: ' + Sys.ie); # if (Sys.firefox)
 * document.write('Firefox: ' + Sys.firefox); # if (Sys.chrome)
 * document.write('Chrome: ' + Sys.chrome); # if (Sys.opera)
 * document.write('Opera: ' + Sys.opera); # if (Sys.safari)
 * document.write('Safari: ' + Sys.safari);
 ******************************************************************************/
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : (s = ua
		.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] : (s = ua
		.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] : (s = ua
		.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] : (s = ua
		.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;

function getCheckboxVals(){
	var checkboxs = $(":checkbox[name=choose]:checked");
	if (checkboxs.length < 1) {
		return "";
	}
	var ids = "";
	checkboxs.each(function() {	//将选中的选项ID组装成以逗号相隔的字符串
		ids += this.value + ",";
	});
	return ids;
}

function gotoPageNum(frm, url) {
	frm.action = url;
	frm.target = "_self";
	if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
		setTimeout(function() {
			frm.submit();
		}, 0);
	} else {
		frm.submit();
	}
}

function getLocations(target){
	var title = target.title;
	var typeName = "";
	var addEvent = "";
	var finalName = "";
	var finalID = "";
	var innerTarget ;
	if(title == '请选择城市'){
		typeName = "区";
		title = "请选择区";
		finalName = "name='locationPK'"; 
		finalID = "id='locationID'";
		innerTarget = $("#area");
	}
	if(title == '请选择省份'){
		typeName = "市";
		title = "请选择城市";
		if($("#area").attr("id") == "area"){
			addEvent = "onChange='getLocations(this);'";
		}else{
			finalName = "name='locationPK'"; 
			finalID = "id='locationID'";
		}
		innerTarget = $("#city");
	}
	if(target.value == "" && target.title == '请选择省份'){
		innerTarget.html("<select><option>--"+typeName+"--</option></select>");
		$("#area").html("<select><option>--区--</option></select>");
		return;
	}else if(target.value == "" && target.title != '请选择省份'){
		innerTarget.html("<select><option>--"+typeName+"--</option></select>");
		return;
	}
	$.get(
		basePath + "/admin/location!getLocations.action?parentID=" + target.value,
		function(data){
			data = eval(data);
			var innerHtml = "<select "+ finalID +" "+ finalName +" "+addEvent+" title='"+title+"'>" +
							"<option value=''>--"+typeName+"--</option>";
			for(var i=0; i<data.length; i++){
				innerHtml += "<option value='"+data[i].id+"'>"+data[i].name+"</option>"
			}
			innerHtml += "</select>";
			innerTarget.html(innerHtml);
		}
	);
}

String.prototype.trim = function() {
	// 用正则表达式将前后空格
	// 用空字符串替代。
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

/**
 * 删除DIV或其它控件
 */
function removediv(DivId) {
	var div = document.getElementById(DivId);
	// div.style.display = "none"; //隐藏而不删除
	div.parentNode.removeChild(div); // 删除
}

/**
 * 取字符长度
 * 
 * @param s
 * @return
 */
function len(s) {
	var l = 0;
	var a = s.split("");
	for ( var i = 0; i < a.length; i++) {
		if (a[i].charCodeAt(0) < 299) {
			l++;
		} else {
			l += 2;
		}
	}
	return l;
}

/**
 * 检测图片上传是否正确
 */
function checkImageUpload(inputValue) {
	var fileext = inputValue.substring(inputValue.lastIndexOf("."),
			inputValue.length)
	fileext = fileext.toLowerCase()
	if ((fileext != '.jpg') && (fileext != '.gif') && (fileext != '.jpeg')
			&& (fileext != '.png') && (fileext != '.bmp')) {
		alert("友情提示：请上传规定格式的图片，谢谢 ！");
		return false;
	} else
		return true;
}

/**
 * 检测密码正确性
 * 
 * @param s
 * @return
 */
function isPasswd(s) {
	var patrn = /^(\w){6,20}$/;
	if (!patrn.exec(s))
		return false
	return true
}

/**
 * 检测电子邮件正确性
 * 
 * @param s
 * @return
 */
function checkEmail(s) {
	var patrn = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
	if (!patrn.exec(s))
		return false
	return true
}
/**
 * 无刷新请求分页
 * 
 * @param eleId
 * @param url
 * @return
 */
function gotoPageNumber(eleId, url) {
	load(url, eleId);
}

/**
 * 无刷新请求
 * 
 * @param url
 * @param eleId
 * @return
 */
function load(url, eleId) {
	$.get(url, null, function(result) {
		$("#" + eleId).html(result);
	});
}

/**
 * 当内容过长时，可以调用此方法来显示完整的内容 展示完整信息
 * 
 * @param id
 *            显示内容的控件ID
 * @param value
 *            完整内容
 * @param showId
 *            点击查看全部内容的控件
 * @param shortValue
 *            缩略内容
 * @return
 */
function showDetail(id, value, showId, shortValue) {
	var show = document.getElementById(showId).innerHTML;
	if (show == '查看详情') {
		document.getElementById(id).innerHTML = value;
		document.getElementById(showId).innerHTML = "隐藏";
	} else {
		document.getElementById(id).innerHTML = shortValue;
		document.getElementById(showId).innerHTML = "查看详情";
	}
}
Date.prototype.format = function(format){
	var o =
	{
	"M+" : this.getMonth()+1, //month
	"d+" : this.getDate(), //day
	"h+" : this.getHours(), //hour
	"m+" : this.getMinutes(), //minute
	"s+" : this.getSeconds(), //second
	"q+" : Math.floor((this.getMonth()+3)/3), //quarter
	"S" : this.getMilliseconds() //millisecond
	}
	if(/(y+)/.test(format))
	format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
	for(var k in o)
	if(new RegExp("("+ k +")").test(format))
	format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
	return format;
	}
